package com.eascs.ticket.configuration.service;

import java.util.List;

import org.springframework.stereotype.Service;

import com.eascs.ticket.common.service.BaseSevice;
import com.eascs.ticket.configuration.entity.TicketAssociationType;
import com.eascs.ticket.configuration.entity.TicketAssociationTypeConstant;

@Service
public class TicketAssociationTypeService extends BaseSevice {

	public List<Object[]> getCustomTicketAssociationType() {
		return this.proxyDao.findObjectsList("select id,name from ticket_association_type where type=? order by group_name", TicketAssociationTypeConstant.TYPE_CUSTOM);
	}

	public List<Object[]> getAllTicketAssociationType() {
		return this.proxyDao.findObjectsList("select id,name from ticket_association_type where 1=1 order by group_name");
	}

	public TicketAssociationType getTicketAssociationTypeTo(String ticketAssociationTypeId) {
		TicketAssociationType ticketAssociationType = this.proxyDao.getById(TicketAssociationType.class, ticketAssociationTypeId);
		TicketAssociationType ticketAssociationTypeQuery = new TicketAssociationType();
		ticketAssociationTypeQuery.setGroupName(ticketAssociationType.getGroupName());
		List<TicketAssociationType> ticketAssociationTypes = this.proxyDao.findEntitysWithAny(ticketAssociationTypeQuery);
		for (TicketAssociationType ticketAssociationType2 : ticketAssociationTypes) {
			if (!ticketAssociationType2.getId().equals(ticketAssociationTypeId))
				return ticketAssociationType2;
		}
		return ticketAssociationType;
	}

}
